from docx import Document

def clean_path(path):
    """
    清洗路径字符串，去除首尾的双引号和空格
    例如：'"C:\\path\\to\\file.docx"' -> 'C:\\path\\to\\file.docx'
    """
    return path.strip().strip('"')

def read_questions_from_word(file_path):
    """从Word文档读取问题列表"""
    cleaned_path = clean_path(file_path)  # 清洗路径
    doc = Document(cleaned_path)
    questions = [para.text.strip() for para in doc.paragraphs if para.text.strip()]
    return questions

def write_answers_to_word(answers, output_path):
    """将答案列表写入Word文档"""
    cleaned_path = clean_path(output_path)  # 清洗路径
    doc = Document()
    for idx, answer in enumerate(answers, 1):
        doc.add_paragraph(f"题目 {idx} 的回答：{answer}")
    doc.save(cleaned_path)